<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>TEST</title>
  </head>
  <body>
    <script>
      var text = ` 
    <svg xmlns="http://www.w3.org/2000/svg" width="100px" height="100px">
      <text
        x="50"
        y="50"
        text-anchor="middle"
        dominant-baseline="middle"
        font-size="100"
      >
        A
      </text>
    </svg>
    `;
      document.body.innerHTML = text;

      text = text
        .replaceAll("\n", " ")
        .replace(/\s+/g, " ")
        .replaceAll(" >", ">")
        .replaceAll("> ", ">")
        .replaceAll(" <", "<")
        .trim();
      console.log(text);

      //*****

      const svgCode = text;
      // 将SVG代码编码为Base64
      const svgBase64 = btoa(unescape(encodeURIComponent(svgCode)));
      // 生成Data URL
      const dataUrl = `data:image/svg+xml;base64,${svgBase64}`;
      // 打印结果
      console.log(dataUrl);
    </script>
  </body>
</html>
